<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>上传照片</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, minimum-scale=1.0, user-scalable=no" />
  <meta name="format-detection" content="telephone=no"/>
  <meta name="viewport" content="width=320,maximum-scale=1.3,user-scalable=no">
  <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>

</head>
<style type="text/css">
     body{
      margin: 0;
      padding: 0;
      text-align: center;
     }
     /*好友查看图片*/
   .layout{
    background: url("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1515045418086&di=8bf79213e84bf79c784a8484d004def4&imgtype=0&src=http%3A%2F%2Fimg4.duitang.com%2Fuploads%2Fitem%2F201308%2F07%2F20130807002041_vGCW3.jpeg");
   }
   .imagebox{
    margin-top: 10px;
    width: 80%;
    height: 400px;
    border: 7px solid white;
    background: white;
    margin: 0 auto;
   }
   .preview{
    width: 275px;
    height: 355px;
    margin-top: 20px;
   }
   .uploadImage,.sharefirend{
    width: 80%;
    height: 50px;
    border:0 solid;
    border-radius: 10px;
    background: #3385ff;
    margin: 20px;
    color: white;
    font-size: 25px;
   }
</style>
<body>
    <div class="layout">     
        <div id="imagebox">
           <img class="preview" src="<?=isset($data['image']) ? $data['image'] : ''?>">
        </div>
        <button class="uploadImage" type="button" id="vt">上传照片</button>
    
        <input id="ig" type="hidden" name="media_id" value="">
     </div>
</body>
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript">
        wx.config({
          // debug: true,
          appId: '<?=$data["appId"]?>',
          timestamp: <?=$data["timestamp"]?>,
          nonceStr: '<?=$data["nonceStr"]?>',
          signature: '<?=$data["signature"]?>',
          jsApiList: [
             'onMenuShareTimeline',
             'onMenuShareAppMessage',
             'chooseImage',
             'uploadImage',
             // 'previewImage',
             // 'downloadImage'
          ]
        });
        wx.ready(function(){       
              $(".uploadImage").click(function(){  
                  wx.chooseImage({
                      count: 1, // 默认9
                      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                      success:function(res){
                           var localId = res.localIds;
                           wx.uploadImage({
                              localId: localId.toString(), // 需要上传的图片的本地ID，由chooseImage接口获得
                              isShowProgressTips: 1, // 默认为1，显示进度提示
                              success: function (res) {
                                  var serverId = res.serverId; // 返回图片的服务器端ID
                                  $.get('http://tt.t.vipds.cn/jssdk/test',
                                    {serverId:serverId,gid:'<?=$data['gid']?>'},//session ???

                                        function(data){
                                           data = JSON.parse(data);//parse解析字符串
                                           if (data.status == 0) {
                                              $(".preview").attr('src','http://img1.nb85.cn/tmp/'+data.msg);//上传图片添加到应有位置
                                           }else{
                                               alert('上传失败');
                                           }
                                        }
                                  );                                
                              }
                            });
                      }
                  });
              });
                 // 分享给朋友
             
                     wx.onMenuShareTimeline({
                        title:'年度照片',
                        link:'http://tt.t.vipds.cn/wegetoauth1?fgid=<?php echo $_SESSION['id']?>',
                        imgUrl:'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1435620528,3911058943&fm=27&gp=0.jpg',
                        success:function(){
                          //用户确认分享后执行的回调函数
                          alert("分享成功！");
                        },
                        cancel:function(){
                          alert("您已取消了分享！")
                          //用户取消分享后执行的回调函数
                        }
                    });
             
                    wx.onMenuShareAppMessage({
                          title:'我的美照',
                          desc:'不看后悔',
                          link:'http://tt.t.vipds.cn/wegetoauth1?fgid=<?php echo $_SESSION['id']?>',
                          imgUrl:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1515240586683&di=2a53642a8938e9755b6abf1436227519&imgtype=0&src=http%3A%2F%2Fc.hiphotos.baidu.com%2Fbaike%2Fpic%2Fitem%2F8644ebf81a4c510f8bef26396a59252dd42aa5ee.jpg',
                          type:'link',
                          dateUrl:'',// 如果type是music或video，则要提供数据链接，默认为空
                           success:function(){
                              // alert("分享成功！");
                           },
                           cancel:function(){
                              alert("您已取消了分享！")
                           }
                    });   
        });
                          
                      
      
//分享到朋友圈分享给朋友
 //              
        
</script>
</html>